package com.jsits.v2x.common.connection.socket;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

public class SocketFactory implements ProtocolCodecFactory
{
	/*
	 * 消息解码类
	 */
	private MessageDecoder decoder;
	
	/*
	 * 消息编码类
	 */
	private MessageEncoder encoder;
	
	public void setSocketBase(SocketBase socketBase) 
	{
		decoder = new MessageDecoder();
		encoder = new MessageEncoder();
		decoder.setSocketBase(socketBase);
	}

	/*
	 * 返回解码类
	 * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getDecoder(org.apache.mina.core.session.IoSession)
	 */
	public ProtocolDecoder getDecoder(IoSession session) throws Exception 
	{
		return decoder;
	}

	/*
	 * 返回编码类
	 * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getEncoder(org.apache.mina.core.session.IoSession)
	 */
	public ProtocolEncoder getEncoder(IoSession session) throws Exception 
	{
		return encoder;
	}

}
